/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package zk;

import entity.vFolder;
import org.zkoss.zul.Treecell;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.TreeitemRenderer;
import org.zkoss.zul.Treerow;
import org.zkoss.zul.SimpleTreeNode;
/**
 *
 * @author nuno
 */
public class TreeRender implements TreeitemRenderer {


	public void render(Treeitem item, Object data) throws Exception {
		SimpleTreeNode t = (SimpleTreeNode)data;

        vFolder folder = (vFolder)t.getData();
		//Contruct treecells
		Treecell Name = new Treecell(folder.getFdname());
        
		Treerow tr = null;
		/*
		 * Since only one treerow is allowed, if treerow is not null,
		 * append treecells to it. If treerow is null, contruct a new
		 * treerow and attach it to item.
		 */
		if(item.getTreerow()==null){
			tr = new Treerow();
			tr.setParent(item);
		}else{
			tr = item.getTreerow();
			tr.getChildren().clear();
		}
		//Attach treecells to treerow
        item.setAttribute("folder", folder);
        Name.setParent(tr);
		item.setOpen(false);
	}

}
